import java.io.IOException ;
import java.net.ServerSocket ;

public class Listen {
   ServerSocket listenSocket ;
   int port ;

   public Listen(int port){
      this.port = port;

      try{
         listenSocket = new ServerSocket(port) ;
      }
      catch (IOException e) {
         System.out.println("Could not listen on port : " + port);
      }
   }

   public void doListenLoop()
   {
      while(true){
         try{
         new ProcessThread(listenSocket.accept()).start();
         }
         catch (IOException e) {
            System.out.println("Accept failed : " + port);
         }
      }
   }

   public static void main(String[] args){
      Listen listen = new Listen(4000);
      listen.doListenLoop() ;
   }
}
